// seajs
seajs.use(['toastr','validate'], function() { 
 
    // toastr.info('你有新消息了！');
    // toastr.success('你有新消息了！');
    // toastr.warning('你有新消息了！');
    // toastr.error('你有新消息了！','错误提示框');

    // 显示 登录 表单
    setTimeout(function(){ 
        $(".fade-in-effect").addClass('in'); 
    }, 1);

    // 设置表单焦点
    $("form#login .form-group:has(.form-control):first .form-control").focus();

    // Validation and Ajax action
    $("form#login").validate({
        rules: {
            username: {
                required: true
            },
            passwd: {
                required: true
            }
        },
        messages: {
            username: {
                required: '请输入账号'
            },
            passwd: {
                required: '请输入密码'
            }
        },
        // Form Processing via AJAX
        submitHandler: function(form){
            
            show_loading_bar(60); // 设置进度条 60%

            $.ajax({
                url: "/index/login/login",
                method: 'POST',
                dataType: 'json',
                data: {
                    username: $(form).find('#username').val(),
                    password: $(form).find('#passwd').val(),
                },
                success: function(resp){
                    
                    show_loading_bar({
                        delay: .5,
                        pct: 100,
                        finish: function(){
                            if(resp.error >= 0){
                                toastr.success(resp.msg);
                                setTimeout(function(){
                                    window.location.href = '/index/index';
                                },1500);
                            }else{
                                toastr.error(resp.msg);
                            }
                                                                    
                        }
                    });
                }
            });
        }
    });
    

});